<?php

$username = $_POST['cuid'];
$password = $_POST['password'];
$count=0;
$prof='Professor';
$admin='Administrator';

$conn = mysql_connect("localhost","gauz","gauz");

if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }
  
mysql_select_db("gx", $conn);
$stmt = mysql_query("select Fname from Candidate where cuid like '$username' and password like '$password'",$conn); 
while ($res = mysql_fetch_array(($stmt)))
{ 
$count++;
}

if($count==1)
{
session_start(); 
//session_register('$username');
$_SESSION['username']=$username;

//$db1 = oci_parse($conn, "select Role from Candidate where CUID like ".$_POST['cuid']); 
$db1 = mysql_query("select Role from Candidate where CUID like '$username'",$conn);
while ($result = mysql_fetch_array($db1))
{
if($result[0]=='Administrator')
{
header('Location: AdministratorHomePage.php');
break;
}
else if($result[0]=='Professor')
{
header('Location: ProfessorHomePage.php');
break;
}
else
{
header('Location: StudentHomePage.php');
break;
}
//echo 'Message'.$result[0];
}
}
else
{
echo "Wrong Username and Password";
}
mysql_close($conn);
?>